const {DB_ADDR, DB_PORT, DB_NAME} = require('../config/config');

function db(success, err, close) {
  // 导入 mongoose 模块
  const mongoose = require("mongoose");

  // 连接 mongodb 数据库
  // mongoose.connect("mongodb://127.0.0.1:27017/accounts");
  mongoose.connect(`mongodb://${DB_ADDR}:${DB_PORT}/${DB_NAME}`);

  // 设置回调
  mongoose.connection.once("open", success);

  mongoose.connection.on("error", err);

  mongoose.connection.on("close", close);
}

module.exports = db;
